package com.vans.common.utils;

import org.apache.commons.lang.StringUtils;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.MonthDay;
import java.time.ZoneOffset;
import java.time.format.DateTimeFormatter;

/**
 * @Description: 利用jdk新特性封装的日期工具类,线程安全
 * @Note: 下面的方法我都没有测试过, 后面再新增完善
 * @Author elle
 * @Date 2020/10/5 12:07
 */
@Deprecated
public class DateUtils {

    private static final String DATE_FORMAT_PATTERN_NONE = "yyyyMMdd";
    private static final String DATE_FORMAT_PATTERN_SLASH = "yyyy/MM/dd";
    private static final String DATE_FORMAT_PATTERN_HYPHEN = "yyyy-MM-dd";
    private static final String DATETIME_FORMAT_PATTERN_BLANK = DATE_FORMAT_PATTERN_NONE + " HH:mm:ss";
    private static final String DATETIME_FORMAT_PATTERN_SLASH = DATE_FORMAT_PATTERN_SLASH +" HH:mm:ss";
    private static final String DATETIME_FORMAT_PATTERN_HYPHEN = DATE_FORMAT_PATTERN_HYPHEN + " HH:mm:ss";

    /**
     * 判断两个日期是否相等
     * @param date1
     * @param date2
     * @return
     */
    public static boolean compareDate(LocalDate date1, LocalDate date2) {
        return date1.equals(date2);
    }

    /**
     * 判断周期性日期
     * @param cycleDate
     * @return
     */
    public static boolean cycleDate(LocalDate cycleDate) {
        LocalDate nowDate = LocalDate.now();

        MonthDay monthDayNow = MonthDay.of(nowDate.getMonth(), nowDate.getDayOfMonth());
        MonthDay monthDayCycle = MonthDay.of(cycleDate.getMonth(), cycleDate.getDayOfMonth());

        return monthDayCycle.equals(monthDayNow);
    }


    /**
     * 日期格式化
     * @param date
     * @return
     */
    public static String formatDate2String(LocalDate date, String formatPatern) {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT_PATTERN_SLASH);
        if (StringUtils.isNotEmpty(formatPatern)) {
            formatter = DateTimeFormatter.ofPattern(formatPatern);
        }
        return date.format(formatter);
    }



}
